import { Button, ButtonProps, Tooltip, TooltipProps } from 'antd';
import lodash from 'lodash';
import React from 'react';

export type SfwButtonProps = ButtonProps & {
  tooltip?: string | TooltipProps;
};

const SfwButton: React.FC<SfwButtonProps> = (props) => {
  const { tooltip, ...restProps } = props;

  const dom = <Button {...restProps} />;

  if (!tooltip) {
    return dom;
  }

  const tooltipProps = lodash.isString(tooltip)
    ? {
        title: tooltip,
      }
    : { ...tooltip };

  return <Tooltip {...tooltipProps}>{dom}</Tooltip>;
};

export default SfwButton;
